const express=require('express');
//引入连接池
const query=require('../util/query.js');
//创建空路由器
let router=express.Router();

//获取首页轮播图列表
router.get('/carousel',async(req,res)=>{
    let sql = "select id,img from album_image where album_id = 6";
    try {
        let result = await query(sql);
        let data=result;

        if (result.length > 0) {
            //图片路径位置从根开始的
            res.send({ code: 1, msg: "加载轮播图成功" ,data});           
        }
        else{
          throw "Query返回记录数不大于0";
        }
    } catch (error) {
        res.send({ code: 0, msg: `加载轮播图失败, error: ${error}` }); //throw err;  
    }
});

router.get("/XXX", async (req, res) => {
    //获取数据,无
    //建sql语句
    let sql=""
    try {
      let result = await query(sql);
  
    } catch (error) {
      res.send({ code: -1, msg: "Query异常,error:" + error});     
      return; 
    }
    
  });

// router.get('/index',(req,res)=>{
//     let retJson={};
//     pool.query(`
//     SELECT cid,img,title,href FROM xz_index_carousel;
//     SELECT pid,title,details,pic,price,href FROM xz_index_product WHERE seq_recommended>0 ORDER BY seq_recommended  LIMIT 6;
//     SELECT pid,title,details,pic,price,href FROM xz_index_product WHERE seq_new_arrival>0 ORDER BY seq_new_arrival LIMIT 6;
//     SELECT pid,title,details,pic,price,href FROM xz_index_product WHERE seq_top_sale>0 ORDER BY seq_top_sale LIMIT 6;
//     `,(err,result)=>{
//         if(err) throw err;
//         retJson.carouselItems=result[0];
//         retJson.recommendedItems=result[1];
//         retJson.newArrialItems=result[2];
//         retJson.topSaleItems=result[3];
//         res.send(retJson);
//     })
// });

module.exports=router;